package com.example.microinvestcommon.entity;
import com.example.microinvestcommon.util.BigDecimalUtil;
import com.example.microinvestcommon.util.SnowflakeIdGeneratorUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@NoArgsConstructor
@AllArgsConstructor
//实体化用户购买股票表
public class BuyStock {
    private Long buyId;
    private Long userId;
    private String stockSymbol;
    private BigDecimal buyPrice;
    private Integer quantity;
    private BigDecimal totalAmount;
    private BigDecimalUtil bigDecimalUtil;

    //存入数据库的构造方法
    public BuyStock(Long userId, String stockSymbol, BigDecimal buyPrice, Integer quantity, SnowflakeIdGeneratorUtil snowflakeIdGenerator) {

        //计算totalAmount的double
        double totalAmountDouble = bigDecimalUtil.multiply(buyPrice.doubleValue(), quantity);
        //double转BigDecimal
        BigDecimal totalAmountDecimal = BigDecimal.valueOf(totalAmountDouble);
        this.buyId=snowflakeIdGenerator.nextId();
        this.userId = userId;
        this.stockSymbol = stockSymbol;
        this.buyPrice = buyPrice;
        this.quantity = quantity;
        this.totalAmount = totalAmountDecimal;
    }




}

